package com.rrx.mapper;

import com.rrx.model.Fettler;
import org.apache.ibatis.annotations.*;



@Mapper
/**
 * 数据库操作
 */
public interface FettlerMapper {
    /**
     * 通过openID查询用户ID
     * @param openid
     * @return
     */
    @Select("select id from users where openid=#{openid}")
    public Integer selectUsersId(@Param("openid") String openid);

    /**
     * 查询师傅ID
     * @param userid
     * @return
     */
    @Select("select id from fettler where userid=#{userid}")
    public  Integer selectFettlerId(@Param("userid") Integer userid);


    /**
     * 查询师傅认证状态
     * @param
     * @return
     */
    @Select("select authstate from fettler where userid=#{id}")
    public Integer selectAuthstate(@Param("id") Integer userid);


//    /**
//     * 查询数据库师傅表的用户ID
//     * @return
//     */
//    @Select("select userid from fettler")
//    public int[] selectFettlerUsersId();

    /**
     * 添加师傅注册信息到数据库
     * @param idcard 身份证号
     * @param imageurl  照片
     * @return
     */
    @Insert("insert into fettler (name,idcard, imageurl, userid) values(#{name}, #{idcard}, #{image}, #{userid})")
    public int addFettler(@Param("name") String name, @Param("idcard") String idcard, @Param("image") String imageurl, @Param("userid") int userid);


    /**
     * 获取所有未认证的师傅
     * @param page
     * @return
     */
    @Select("select * from fettler where adminid is null limit #{page}, 10")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "idcard", property = "idcard"),
            @Result(column = "imageurl", property = "imageUrl"),
            @Result(column = "authtime", property = "authTime"),
            @Result(column = "userid", property = "userId")
    })
    public Fettler[] getUnauthFettler(@Param("page") int page);

    @Select("select count(id) from fettler where userid = #{userid}")
    public int isFettlerExsits(@Param("userid") int userid);
}
